import request from '../utils/request.js'

interface Response {
    code?: number,
    data: any
}

/**
 * 获取banner的接口
 */
export const getBannerAPI = () => request.get('/banner/getBanner')

/**
 * 获取当前用户信息
 */
export const getUserInfoAPI = (user_id: number) => request.get('/user/getUserInfo', {
    user_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 获取所有文章数据
 */
export const getArticleAPI = (type_id: number, page: number): Promise<Response> =>  request.get('/article/getArticle', {
    type_id,
    limit: 5,
    page
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 请求详情页数据
 */
export const getDetailAPI = (article_id: string, user_id: string) => request.get('/article/getDetail', {
    article_id, user_id
})


/**
 * 请求评论数据
 */
export const getReviewListAPI = (article_id: string) => request.get('/article/getReviewList', {
    article_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 发表评论
 */
export const postReviewAPI = (review, user, article_id) => request.post('/article/postReview', {
    review,
    user,
    article_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 回复评论
 */
export const recoverReviewAPI = (review_content, review_extend, user, article_id) => request.post('/article/recoverReview', {
    review_content,
    review_extend,
    user,
    article_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})


/**
 * 判断当前文章是否已经被收藏
 */
export const checkCollectAPI = (user_id, article_id) => request.get('/article/checkCollect', {
    user_id,
    article_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 点击收藏按钮
 */
export const collectAPI = (user_id, article_id, collect_num, collect_status) => request.post('/article/collect', {
    user_id,
    article_id,
    collect_num,
    collect_status
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})


/**
 * 判断当前文章是否已经被点赞
 */
export const checkLikeAPI = (user_id, article_id) => request.get('/article/checkLike', {
    user_id,
    article_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 点击点赞按钮
 */
export const likeAPI = (user_id, article_id, like_num, like_status) => request.post('/article/like', {
    user_id,
    article_id,
    like_num,
    like_status
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 请求文章作者的最近文章
 */
export const getLastArticleListAPI = (article_author_id) => request.get('/article/lastArticleList', {
    article_author_id
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

/**
 * 模糊查询请求
 */
export const searchAPI = (text) => request.get('/article/search', {
    text
}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})


/**
 * 获取最近更新的作者以及文章数据
 */
export const getNearListAPI = () => request.get('/article/getNearList', {

}, {
    headers: {
        "authorization": localStorage.getItem('token')
    },
})

